package com.leetcode.dynamic_programming;

import java.util.Deque;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;

/**
 * @author Dennis Li
 * @date 2020/7/30 20:10
 */
public class LongestPalindrome_5 {

    public String longestPalindrome(String s) {
        if(s.equals("")) return "";
        int len = s.length();
        boolean[][] isPalindrome = new boolean[len][len];
        for (int i = 0; i < len; i++) {
            isPalindrome[i][i] = true;
        }
        char[] chars = s.toCharArray();
        int maxLen = 0, start = 0, end = 0;
        for (int i = 0; i < len; i++) {
            for (int j = i + 1; j < len; j++) {
                if (chars[i] == chars[j]) {
                    isPalindrome[i][j] = j - i == 1 || isPalindrome[i + 1][j - 1];
                    if (isPalindrome[i][j] && maxLen < j - i) {
                        start = i;
                        end = j;
                        maxLen = j - i;
                    }
                } else {
                    isPalindrome[i][j] = false;
                }
            }
        }

        return s.substring(start, end + 1);
    }

    public static void main(String[] args) {
        ClassLoader classLoader = String.class.getClassLoader();

        new CopyOnWriteArrayList<Integer>();
        new CopyOnWriteArraySet<Integer>();

        new AtomicLong();

        Set<Integer> set = new ConcurrentSkipListSet<>();

        ClassLoader parent = classLoader.getParent();

        System.out.println("Complete");
    }

}
